function smap=verification_starhash(ww_cal,sao,tabs,h2h,hkey,k,bins,bin_start)

nbins=256;

smap=-ones(size(ww_cal,1),1);
ww_caln=zeros(size(ww_cal));
% ww_cal=ww_cal./repmat(max(abs(ww_cal),[],2),1,size(ww_cal,2));

d=uint32([0,0,0; 0,0,1; 0,1,0; 0,1,1;
   0,0,0; 0,0,1; 1,0,0; 1,0,1;
   0,0,0; 0,1,0; 1,0,0; 1,1,0]);

[all_m,all_id]=max(abs(ww_cal),[],2);
ww_caln=uint32(floor((ww_cal./[all_m,all_m,all_m]+1)*nbins/2));
all_val=uint32(zeros(4,size(ww_cal,1)));
for i=1:size(ww_cal,1)
    id=(all_id(i)-1)*4;
%     all_val(:,i)=(ww_caln(i,1)+d(id:id+3,1))*k*k+(ww_caln(i,2)+d(id:id+3,2))*k+ww_caln(i,3)+d(id:id+3,3);
    for j=1:4
        all_val(j,i)=(ww_caln(i,1)+d(id+j,1))*k*k+(ww_caln(i,2)+d(id+j,2))*k+ww_caln(i,3)+d(id+j,3);
    end
end
% all_h=reshape(phash_mex(all_val(:)),4,[]);
all_h=phash_mex(all_val);

for i=1:size(ww_cal,1)
%     [m,id]=max(abs(ww_cal(i,:)));
%     ww_caln(i,:)=floor((ww_cal(i,:)/m+1)*nbins/2);
%     ww_cal(i,:)=ww_cal(i,:)/m;
%     id=(all_id(i)-1)*4;
    m=10000;
    for j=1:4
%         val=uint32((ww_caln(i,1)+d(id+j,1))*k*k+(ww_caln(i,2)+d(id+j,2))*k+ww_caln(i,3)+d(id+j,3));
%         val=mod(uint64(val)+3115904703,2^32);
%         val=bitxor(val,bitshift(val,-16));
%         val=mod(val+bitshift(val,8),2^32);
%         val=bitxor(val,bitshift(val,-4));
%         b=bitand(bitshift(val,-8),2047);
%         a=mod(bitshift(mod(val+mod(bitshift(val,9),2^32),2^32),-20),2^32);
%         h=phash_mex(val);
        h=all_h(j,i);
        val=all_val(j,i);
        if h>=size(h2h,1)
            continue;
        end
        if hkey(h+1)~=val
            continue;
        end
        h=h2h(h+1);
        hs=bins(bin_start(h):bin_start(h+1)-1);
        if numel(hs)>1
            for h=hs'
%                 t=norm(sao(h,2:4)-ww_cal(i,:));
                t=(sao(h,2)-ww_cal(i,1))^2+(sao(h,3)-ww_cal(i,2))^2+(sao(h,4)-ww_cal(i,3))^2;
                if t<(0.5/2048*8*pi/180)^2 && t<m
                    m=t;
                    smap(i)=h;
                end
            end
        else
            h=hs;
%             t=norm(sao(h,2:4)-ww_cal(i,:));
            t=(sao(h,2)-ww_cal(i,1))^2+(sao(h,3)-ww_cal(i,2))^2+(sao(h,4)-ww_cal(i,3))^2;
%             if t<(0.5/2048*8*pi/180)^2 && t<m
            if t<(atand(0.0045/25)*5*pi/180)^2 && t<m
                m=t;
                smap(i)=h;
            end
        end
    end
end